<?php
/**
 * Created by PhpStorm.
 * User: EZ
 * Date: 2017/5/25
 * Time: 11:35
 */

namespace app\index\controller;
use core\Route;
use core\Db;
use lib\Redis;
use lib\Pinyin;
class Index extends  Route{
    public function index(){

        echo get_url();
        p($_SERVER);
        $this->display();
    }

    public function test(){
        $arr = array(3,5,8,4,9,6,1,7,2);
        $a=QSort($arr);
        p($a);die;
    }
    public function a(){

        echo "访问了".__METHOD__."方法<br />";
        p($_GET);
    }

    public function client(){
//        $client=self::hproseClient("http://www.zdws.com/index.php/index/server",false);
        $client=self::hproseClient("http://www.tp57cai.com/index.php/api/server",false);
        $content=$client->hello('赵大伟');
        p($content);

    }

    public function par(){
        $path_info = isset($_SERVER['PATH_INFO']) ? trim($_SERVER['PATH_INFO'],'/') : "";
        p($path_info);die;
        if(!empty($_SERVER['QUERY_STRING'])){
            $query_string = urldecode($_SERVER['QUERY_STRING']);
            $query_string = str_replace("&","/",$query_string);
            $query_string = str_replace("=","/",$query_string);
            $path_info .= "/".$query_string;
        }
        $arr = explode("/",$path_info);
        $this->action = trim(array_shift($arr),",");
        $this->method = array_shift($arr);
        for($i=0;$i<count($arr);$i=$i+2){
            $this->params[$arr[$i]] = $arr[$i+1];
        }
        global $_REQUEST;
        global $_POST;
        global $_GET;
        $_GET = array_merge($this->params,$_GET);

        $input = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : file_get_contents("php://input");
        $post = json_decode($input,TRUE);
        if(!empty($post))$_POST = array_merge($_POST,$post);

        $_REQUEST = array_merge($_POST,$_GET,$_REQUEST);
        if(!empty($_REQUEST)){
            foreach($_REQUEST as $v){
                if(!check_sql($v))E(array('status'=>'error','msg'=>'请修改您的请求数据'),true);
            }
        }
        $_REQUEST['_action_'] = $this->action;
        $_REQUEST['_method_'] = $this->method;
        define('__ACTION__',$this->action);
        define('__FUNC__',$this->method);
        define('__PRIVILEGES__',$this->action.'.'.$this->method);
        if(__PRIVILEGES__ != '_Image.do_upload')session_start();
    }


}